var NH_Room = function () {

    return {
        init: function () {
            $('td.set-room a.btn').click(function () {
                var _td = $(this).parent();
                var obj = {};
                obj['team'] = $(_td).attr('team');
                obj['level'] = $(_td).attr('level');
                obj['crew'] = $(_td).attr('crew');
                obj['classname'] = $(_td).attr('classname');
                obj['location'] = $(_td).attr('location');
                obj['note'] = $(_td).attr('note');
                
                $('#responsive').html(tmpl('room-tmpl', obj));
                
                $('#responsive').modal({
                    focusOn: 'input:text'
                })
                .find('.btn-save').click(function () {
                    
                    var tmp_inputs = $("input, textarea, select", $('#responsive'));
                    var obj = {};
                    
                    $.map(tmp_inputs, function(n, i) {
                        obj[$(n).attr('name')] = $(n).val();
                    });
                    
                    $('[team="'+obj.team+'"][level="'+obj.level+'"][crew="'+obj.crew+'"]').parent()
                    .find('td.result').html('<img src="assets/img/loading.gif"/>')
                    
                    $.ajax({
                        url: 'room_execute.php?action=update-location',
                        type: 'post',
                        dataType: 'json',
                        data: $.param(obj),
                        success:function(response){
                            if (response.code = 200) {
                                $('[team="'+response.data.team+'"][level="'+response.data.level+'"][crew="'+response.data.crew+'"]').parent()
                                .find('td.result').html(response.data.location)
                                .next().html(response.data.note);
                            }
                        }
                    });
                    
                    $('.close','#responsive').click();
                });
            });
        }
    };
}();